package com.meme.editor.gui.sprite2d;


import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;

import com.meme.editor.model.sprite2d.Tiled2dLayer;

import java.awt.Color;
import java.awt.SystemColor;
import java.awt.Component;


public class Tiled2dLayerListCellRenderer extends DefaultListCellRenderer 
{

	public static Tiled2dLayerStatus getTiled2dLayerStatus (Tiled2dLayer layer)
	{
		  Tiled2dLayerStatus layerStatus = (Tiled2dLayerStatus) layer.getUserObject();
		  if ( layerStatus == null )
		  {
			  layerStatus = new Tiled2dLayerStatus ();
			  layer.setUserObject (layerStatus);
		  }

		  return layerStatus;
	}
	

	
    public Component getListCellRendererComponent(JList list,
                                                Object value,
                                                int index,
                                                boolean isSelected,
                                                boolean hasFocus) 
    {
	  JLabel label = (JLabel) super.getListCellRendererComponent(list,
                                                 value,
                                                 index,
                                                 isSelected,
                                                 hasFocus);
	  
	  if ( value instanceof Tiled2dLayer)
	  {
		  Tiled2dLayer layer = (Tiled2dLayer) value;
		  Tiled2dLayerStatus layerStatus = getTiled2dLayerStatus ( layer );
		  
		  String labelText = "";
		  
		  if (layerStatus.isVisible())
		  {
			  //label.setForeground(SystemColor.text);
			  labelText = labelText + "@ ";
		  }
		  else
		  {
			  //label.setForeground(SystemColor.textInactiveText);
			  labelText = labelText + "  ";
		  }
		  
		  if (layerStatus.isLocked())
		  {
			  //label.setForeground(SystemColor.text);
			  labelText = labelText + "x : ";
		  }
		  else
		  {
			  //label.setForeground(SystemColor.textInactiveText);
			  labelText = labelText + "  : ";
		  }
		  
		  labelText = labelText + label.getText();
		  label.setText (labelText);
	  }

    
	  return(label);
  	}
}

